public class MyBinaryTree {
    //二叉树
    static class BinaryTree {
        public BinaryTree left;
        public BinaryTree right;
        public int val;

        public BinaryTree(int val) {
            this.val = val;
        }
    }
    //头节点
    public BinaryTree root;

    //初始化二叉树
    public void initBinaryTree() {
        BinaryTree A = new BinaryTree(1);
        BinaryTree B = new BinaryTree(2);
        BinaryTree C = new BinaryTree(3);
        BinaryTree D = new BinaryTree(4);
        A.left = B;
        A.right = C;
        C.left = D;
        root = A;
    }

    //
    public BinaryTree findNode(BinaryTree root,int num) {
        if (root == null) {
            return null;
        }
        if (root.val == num) {
            return root;
        }
        BinaryTree leftTree = findNode(root.left, root.val);
        if (leftTree != null) {
            return leftTree;
        }
        BinaryTree rightTree = findNode(root.right,root.val);
        if (rightTree != null) {
            return rightTree;
        }
        return  null;
    }

    public boolean isSameTree(BinaryTree tree1, BinaryTree tree2) {
        if (tree1 == null && tree2 == null) {
            return true;
        }
        if ((tree1 == null && tree2 != null) || (tree1 != null && tree2 == null)) {
            return false;
        }

        if (tree1.val != tree2.val) {
            return false;
        }

        boolean leftTree = isSameTree(tree1.left,tree2.left);
        boolean rightTree = isSameTree(tree1.right, tree2.right);
        return  leftTree && rightTree;
    }
}
